import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/goods/model/goods_entity.dart';
import 'package:tender_flutter/page/supplier/model/supplier_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:tender_flutter/widgets/net_image.dart';

class GoodsCell extends StatelessWidget {
  const GoodsCell({Key key, this.data, this.onTap}) : super(key: key);

  final GoodsList data;
  final GestureTapCallback onTap;

  @override
  Widget build(BuildContext context) {
    return AspectRatio(aspectRatio: 3,child: InkWell(onTap: onTap,child: _initCell()));
  }

  Widget _initCell(){
    return Container(
        padding: EdgeInsets.all(5),
        width: double.infinity,
        child:Row(children: <Widget>[
          // 圆角图片
          ClipRRect(
              borderRadius: BorderRadius.circular(10.0),
              child: MyNetImage(
                url:
                data.pic,
                radius: BorderRadius.circular(ScreenAdapter.width(14)),
                width: ScreenAdapter.width(168),
                height: ScreenAdapter.width(168),
              )
          ),
          // 用SizedBox增加间距
          SizedBox(
            width: 8,
          ),
          // 右侧的商品描述信息
          Expanded(child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              SizedBox(
                height: 15,
              ),
              Expanded(child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    padding:
                    EdgeInsets.only(left: 1, right: 1, top: 0, bottom: 0),
                    decoration: BoxDecoration(
                        color: Colors.red,
                        border:
                        Border.all(color: Color(0xFFFF0000), width: 0.5),
                        borderRadius: BorderRadius.all(Radius.circular(5))),
                    child: Text(
                      '特惠',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 10,
                      ),
                    ),
                  ),
                  SizedBox(width: 3),
                  // 商品标题
                  Expanded(child: Text(
                    data.title ?? "",
                    style: TextStyle(
                      color: Colors.black,
                    ),
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    softWrap: true,
                  ))
                ],
              )),
              SizedBox(
                height: 3,
              ),
              // 两个横向标签
              Row(
                children: <Widget>[
                  Container(
                    padding:
                    EdgeInsets.only(left: 3, right: 3, top: 1, bottom: 1),
                    decoration: BoxDecoration(
                        border:
                        Border.all(color: Color(0xFFFF0000), width: 0.5),
                        borderRadius: BorderRadius.all(Radius.circular(5))),
                    child: Text(
                      '优选放心购',
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 10,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 10,
                  ),
                  Container(
                    padding:
                    EdgeInsets.only(left: 3, right: 3, top: 1, bottom: 1),
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.deepOrangeAccent, width: 0.5),
                        borderRadius: BorderRadius.all(Radius.circular(5))),
                    child: Text(
                      '包邮',
                      style: TextStyle(
                        color: Colors.deepOrangeAccent,
                        fontSize: 10,
                      ),
                    ),
                  )
                ],
              ),
              SizedBox(
                height: 3,
              ),
              // 价格信息
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  Text(
                    '￥',
                    style: TextStyle(color: Colors.orange, fontSize: 12),
                  ),
                  Text(
                    "${data.priceN}",
                    style: TextStyle(color: Colors.orange, fontSize: 20),
                  ),
                  SizedBox(
                    width: 10,
                  ),
                  Text(
                    '${Random().nextInt(3)}人付款',
                    style: TextStyle(color: Colors.grey, fontSize: 12),
                  ),
                ],
              ),
              SizedBox(
                height: 8,
              ),
            ],
          ))
        ]));
  }
}
